package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.CulturalRelic;
import com.haoan.index.service.CulturalRelicService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 文物Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="文物",tags = "文物")
@RestController
@RequestMapping("/index/culturalRelic")
public class CulturalRelicController extends BaseController
{
    @Resource
    private CulturalRelicService culturalRelicService;

    /**
     * 点赞
     */
    @ApiOperation("点赞")
    @Anonymous
    @GetMapping(value = "thumbsUp/{id}")
    public AjaxResult thumbsUp(@PathVariable("id") Long id)
    {
        CulturalRelic culturalRelic = culturalRelicService.selectCulturalRelicById(id);
        culturalRelic.setLikes(culturalRelic.getLikes()+1L);
        culturalRelicService.updateCulturalRelic(culturalRelic);
        return success(culturalRelic);
    }

    /**
     * 查询文物列表
     */
    @ApiOperation("查询文物列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(CulturalRelic culturalRelic)
    {
        startPage();
        List<CulturalRelic> list = culturalRelicService.selectCulturalRelicList(culturalRelic);
        return getDataTable(list);
    }

    /**
     * 导出文物列表
     */
    @ApiOperation("导出文物列表")
    @PreAuthorize("@ss.hasPermi('index:culturalRelic:export')")
    @Log(title = "文物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CulturalRelic culturalRelic)
    {
        List<CulturalRelic> list = culturalRelicService.selectCulturalRelicList(culturalRelic);
        ExcelUtil<CulturalRelic> util = new ExcelUtil<CulturalRelic>(CulturalRelic.class);
        util.exportExcel(response, list, "文物数据");
    }

    /**
     * 获取文物详细信息
     */
    @ApiOperation("获取文物详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(culturalRelicService.selectCulturalRelicById(id));
    }

    /**
     * 新增文物
     */
    @ApiOperation("新增文物")
    @PreAuthorize("@ss.hasPermi('index:culturalRelic:add')")
    @Log(title = "文物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CulturalRelic culturalRelic)
    {
        return toAjax(culturalRelicService.insertCulturalRelic(culturalRelic));
    }

    /**
     * 修改文物
     */
    @ApiOperation("修改文物")
    @PreAuthorize("@ss.hasPermi('index:culturalRelic:edit')")
    @Log(title = "文物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CulturalRelic culturalRelic)
    {
        return toAjax(culturalRelicService.updateCulturalRelic(culturalRelic));
    }

    /**
     * 删除文物
     */
    @ApiOperation("删除文物")
    @PreAuthorize("@ss.hasPermi('index:culturalRelic:remove')")
    @Log(title = "文物", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(culturalRelicService.deleteCulturalRelicByIds(ids));
    }
}
